﻿
var currentPage = 1; // 当前页
var pageSize = 30; // 每页显示多少条
var pageall = 0; // 总页数
var total = 0; // 总记录数
var phototype = 1;

$(document).ready(function() {
    var id = LexunJS.GetQueryString("id");  // 楼盘ID

    // 修改
    if (id > 0) {
        $("#hID").val(id);
        showDetail(id);
        showBuild(1);       // 默认显示栋阁标签
    }
});

//修改栋阁别名        
function add(id) {
    $("#hBuildID").val(id);
    openLayer("divList", "divLayer1");
}

//提交添加别名
function UpdateBuild() {
    var idlist = $("#hBuildID").val();      // 栋阁ID 如:2322,2325,2324
    var name = document.getElementById("iBuild").value;

    if (name.length = 0 || name.replace(/(^\s*)|(\s*$)/g, "") == "") {
        alert("别名不能为空！");
        document.getElementById("iBuild").focus();
        return false;
    }
    var tname = 't_build';
    var type = 2; //1.代表申请楼盘别名,2栋阁别名3，房号别名
    var cName = document.getElementById("iUserName").value;
    var cDept = document.getElementById("iUserDept").value;
    var cDId = document.getElementById("ideptid").value;
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerRoomNo.ashx',
        data: 'act=ub&idlist=' + idlist + '&name=' + name + '&type=' + type + '&tname=' + tname + '&cName=' + cName + '&Cdept=' + cDept + '&cDId=' + cDId,
        timeout: '10000',
        error: function() {
            alert("修改失败！");
        }, success: function(json) {
            alert(json);
            closeLayer();
            //showBuild(1);       // 默认显示栋阁标签
        }
    });
}

// 批量申请别名
function addVolume() {
    var IDList = document.getElementById("hID").value;
    if (IDList == "") {
        alert("请先选择您要批量申请别名的行！");
        return false;
    }

    openLayer("divList", "divLayer1");
}

// 弹出iframe层(房号)
function roomNoDialog(id) {
    var path = "RoomList.aspx?id=" + id;
    var parameter = "";
    var style = "dialogWidth:638px; dialogHeight:563px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";

    window.showModalDialog(path, parameter, style);
}

// 弹出iframe层(栋阁添加|修改)
function buildDialog(id) {
    var eid = $("#hID").val();
    var path = "BuildAdd.aspx?eid=" + eid + "&id=" + id+"&p+"+Math.random();
    var parameter = "";
    var style = "dialogWidth:556px; dialogHeight:350px; status:0;scroll:0; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";

    window.showModalDialog(path, parameter, style);
    showBuild(currentPage);
}

function buildDialogBatch() {
    var eid = $("#hID").val();
    var path = "BatchBuildRoom.aspx?eid=" + eid;
    var parameter = "";
    var style = "dialogWidth:620px; dialogHeight:350px; status:0;scroll:0; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";
    window.showModalDialog(path, parameter, style);
    showBuild(currentPage);
}

// 查询详细
function showDetail(id) {
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerIndex.ashx',
        data: 'act=estate_detail&id=' + id,
        timeout: '10000',
        error: function() {
            alert("修改失败！");
        },
        success: function(json) {
            showDetailCallBack(json);
        }
    });
}

function showDetailCallBack(response) {
    var json = eval("(" + response + ")");
    var record = json.record;

    if (record == null || record.length == 0) return;

    var recordLength = record.length;
    for (var i = 0; i < recordLength; i++) {
        $("#sName").text(record[i].name);

        if (record[i].othername != "")
            $("#sOtherName").text("(" + record[i].othername + ")");

        $("#sArea").text(record[i].cityname + record[i].areaname);
        $("#sAddress").text(record[i].address);
        $("#sAroundCondition").text(record[i].aroundcondition);
        $("#sUsage").text(LexunJS.GetUsageNameById(record[i].usage));
        $("#sType").text(record[i].type);
        $("#sPropertyCompany").text(record[i].propertycompany);
        $("#sDescription").text(record[i].description);
        $("#sPropertyTel").text(record[i].propertytel);
        $("#sPropertyLevel").text(record[i].propertylevel);
        $("#sCompleteDate").text(record[i].completedate);
        $("#sTrafficCondition").text(record[i].trafficcondition);
        $("#sConstructionArea").text(record[i].constructionarea);
        $("#sFamilyTotal").text(record[i].familytotal);

        if (record[i].isvalid == 0)
            $("#spanIsValid").text("有效");
        else if (record[i].isvalid == 1)
            $("#spanIsValid").text("待审核");
        else if (record[i].isvalid == 2)
            $("#spanIsValid").text("无效");

        $("#sConstruction").text(record[i].construction);
        $("#sRemark").text(record[i].remark);
        $("#sSalesFare").text(record[i].salesfare);
        $("#sPropertyFare").text(record[i].propertyfare);
        $("#sRealestateName").text(record[i].realestatename);
        $("#sRealestateTel").text(record[i].realestatetel);
        $("#sRegisterdate").text(record[i].registerdate);
        $("#sRegistername").text(record[i].registername);
        $("#sUpdatedate").text(record[i].updatedate);
        $("#sUpdatename").text(record[i].updatename);
    }
}

// 跳转 num(跳到第几个标签)
function go_to(num) {
 
    var tabs = document.getElementById("div_tab").getElementsByTagName("a");
    for (var i = 1; i <= tabs.length; i++) {
        if (num == i) {
            tabs[i - 1].className = "y";
            document.getElementById("div" + i).style.display = "block";
        } else {
            tabs[i - 1].className = "";
            document.getElementById("div" + i).style.display = "none";
        }
    }
    if (num != 7) {
        document.getElementById("div8").style.display = "none";
        document.getElementById("div9").style.display = "none";
    }
    if (num != 2) {
        document.getElementById('div11').style.display = "none";
        document.getElementById('div12').style.display = "none";
    } else {
    showdele_cb(); //栋阁删除
    document.getElementById('div12').style.display = "";
    }
    
    var id = $("#hID").val();

    switch (num) {
        case 1:
            showDetail(id);               // 详细信息
            break;
                        case 2:
                            showBuild(1);               // 栋阁详情 1第一页 
                           
                            break; 
        case 3:
            $("#hTradeTypeID").val("1");
            showHousing(1);             // 出售房源
            break;
        case 4:
            $("#hTradeTypeID").val("2");
            showHousing(1);             // 出租房源
            break;
        case 5:
            showEstatePic(1, 'div5_content');   // 小区照片
            break;
        case 6:
            showEstatePic(2, 'div6_content');   // 小区房型
            break;
        case 7:
            showT_roomno(1);             // 全部房号
            break;
       
    }
}
window.onload = function() {
    showdele_cb();
}
//小区栋阁 审核删除 按钮显示
function showdele_cb() {
    var hCompetencesIsAdd = $("#hCompetencesIsAdd").val();                  // 0不允许添加 1允许添加
    var hCompetencesIsEdit = $("#hCompetencesIsEdit").val();                // 0不允许修改 1允许修改
    var hCompetencesIsOtherName = $("#hCompetencesIsOtherName").val();      // 0不允许申请别名 1允许申请别名
    var hCompetencesIsCheck = $("#hCompetencesIsCheck").val();              // 0不允许审核楼盘字典 1允许审核楼盘字典

    var hCompetencesIsDel = $("#hCompetencesIsDel").val();              // 删除栋阁

    var RoleId = document.getElementById("hRoleId").value;  //删除栋阁
//    if (hCompetencesIsEdit == 1 && hCompetencesIsOtherName == 1) {
//       // if (RoleId == 1) {//系统管理员删除栋阁
//            document.getElementById('div11').style.display = "";
//       // }
//       // else {
//           // document.getElementById('div11').style.display = "none";
//       // }
//    }
//    else {
//        document.getElementById('div11').style.display = "none";
//    }


    document.getElementById('div11').style.display = "";
        
            if (hCompetencesIsDel == 1) {
                $("#Button6").attr("disabled", "");
            } else {
            $("#Button6").attr("disabled", "true");
        }
        if (hCompetencesIsCheck == 1) {
            $("#Button5").attr("disabled", "");
        } else {
            $("#Button5").attr("disabled", "true");
        }
        if (hCompetencesIsCheck != 1 && hCompetencesIsDel != 1)
        { document.getElementById('div11').style.display = "none"; }
}

//显示审核 删除按钮
function showdele() {
    var hCompetencesIsAdd = $("#hCompetencesIsAdd").val();                  // 0不允许添加 1允许添加
    var hCompetencesIsEdit = $("#hCompetencesIsEdit").val();                // 0不允许修改 1允许修改
    var hCompetencesIsCheck = $("#hCompetencesIsCheck").val();              // 0不允许审核楼盘字典 1允许审核楼盘字典
    var hCompetencesIsOtherName = $("#hCompetencesIsOtherName").val();      // 0不允许申请别名 1允许申请别名
    var hCompetencesIsDel = $("#hCompetencesIsDel").val();              // 删除栋阁
    var RoleId = document.getElementById("hRoleId").value;  //删除栋阁

    if (hCompetencesIsEdit == 1 && hCompetencesIsOtherName == 1) {
        if (RoleId == 1) {//系统管理员删除栋阁
            document.getElementById('div9').style.display = "";
            document.getElementById('div10').style.display = "";
        }
    }

    if (hCompetencesIsCheck == 1) {
        document.getElementById('div9').style.display = "";
        if (hCompetencesIsDel != 1) {
            $("#Button4").attr("disabled", "true");
        }
       
    }
    if (hCompetencesIsDel == 1) {
        document.getElementById('div9').style.display = "";
        if (hCompetencesIsCheck != 1) {
            $("#Button6").attr("disabled", "true");
        }
    }  
}
// 全部房号
function showT_roomno(currentPage) {
    document.getElementById('div8').style.display = "";
    showdele();

    var bname = document.getElementById('dropdg').options[document.getElementById('dropdg').selectedIndex].text;
    var isVsild = $('#slisvaild').val();
    var eid = $("#hID").val();
    if (eid <= 0) return;
    var divId = "div7";
    $("#" + divId).html("<img src=\"../images/loading.gif\" />"); // 清空列表
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerHousing.ashx',
        data: 'act=t_roomno_list_bytradetype&page=' + currentPage + '&bname=' + bname + '&isVsild=' + isVsild + '&pagesize=' + 50 + '&eid=' + eid,
        timeout: '10000',
        error: function() {
            alert("查询失败！");
        },
        success: function(json) {
        showT_roomnoCK(json);
        }
    });
}

function audit(obj) {
    var hCompetencesIsAdd = $("#hCompetencesIsAdd").val();                  // 0不允许添加 1允许添加
    var hCompetencesIsEdit = $("#hCompetencesIsEdit").val();                // 0不允许修改 1允许修改
    var hCompetencesIsOtherName = $("#hCompetencesIsOtherName").val();      // 0不允许申请别名 1允许申请别名
    var RoleId = document.getElementById("hRoleId").value;  //删除栋阁
    if (hCompetencesIsEdit == 1 && hCompetencesIsOtherName == 1) {
        if (RoleId == 1) {//系统管理员删除栋阁
            if (document.getElementById('hidckfk').value != "" && document.getElementById('hidckfk').value != "0") {
                showT_roomno_ss(1, document.getElementById('hidckfk').value, obj);
            }
        }
        var hCompetencesIsDel = $("#hCompetencesIsDel").val();                // 删除栋阁
        if (hCompetencesIsDel == 1) {
            if (document.getElementById('hidckfk').value != "" && document.getElementById('hidckfk').value != "0") {
                showT_roomno_ss(1, document.getElementById('hidckfk').value, obj);
            }
        }
    }

}
//删除 修改
function showT_roomno_ss(currentPage, did, type) {
    if (type == 1) {
        if (!confirm('确定要审核？')) {
            return;
        }
    }
    if (type == 2) {
        if (!confirm('确定要删除？')) {
            return;
        }
    }
    var roomnoid = did;
    document.getElementById('div8').style.display = "";
    document.getElementById('div9').style.display = "";
    var bname = document.getElementById('dropdg').options[document.getElementById('dropdg').selectedIndex].text;
    var isVsild = $('#slisvaild').val();
    var eid = $("#hID").val();
    if (eid <= 0) return;
    var divId = "div7";
    $("#" + divId).html("<img src=\"../images/loading.gif\" />"); // 清空列表
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerHousing.ashx',
        data: 'act=t_roomno_list_ss&page=' + currentPage + '&type=' + type + '&roomnoid=' + roomnoid + '&isVsild=' + isVsild + '&pagesize=' + 50 + '&eid=' + eid,
        timeout: '10000',
        error: function() {
            alert("查询失败！");
        },
        success: function(json) {
            showT_roomnoCK(json);
        }
    });
}
//删除 修改
function showT_roomno_type(currentPage, did) {
    if (!confirm('确定要删除？')) {
        return;
    }
    var roomnoid = did;
    document.getElementById('div8').style.display = "";
    document.getElementById('div9').style.display = "";
    
     var bname = document.getElementById('dropdg').options[document.getElementById('dropdg').selectedIndex].text;

    var isVsild = $('#slisvaild').val();
    var eid = $("#hID").val();
    if (eid <= 0) return;
    var divId = "div7";
    $("#" + divId).html("<img src=\"../images/loading.gif\" />"); // 清空列表
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerHousing.ashx',
        data: 'act=t_roomno_list_ss&page=' + currentPage + '&type=2&roomnoid=' + roomnoid + '&bname=' + bname + '&isVsild=' + isVsild + '&pagesize=' + 50 + '&eid=' + eid,
        timeout: '10000',
        error: function() {
            alert("查询失败！");
        },
        success: function(json) {
            showT_roomnoCK(json);
        }
    });
}

function SI(roomnoid) {
    ShowIframe("EstateDetail_1.aspx?roomnoid="+roomnoid, 450, 200, '');
}
function showT_roomnoCK(response) {
    var json = eval("(" + response + ")");
    var record = json.record;
    // 权限判断
    var hCompetencesIsAdd = $("#hCompetencesIsAdd").val();                  // 0不允许添加 1允许添加
    var hCompetencesIsEdit = $("#hCompetencesIsEdit").val();                // 0不允许修改 1允许修改
    var hCompetencesIsDel = $("#hCompetencesIsDel").val();                // 删除栋阁
    
    var hCompetencesIsOtherName = $("#hCompetencesIsOtherName").val();      // 0不允许申请别名 1允许申请别名
    var RoleId = document.getElementById("hRoleId").value;  //删除栋阁

    var page = json.page;
    currentPage = page.currentpage;
    pageall = parseInt(page.pageall);
    total = page.total;
  
    var arr = [];
    arr.push("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" >");
    arr.push("<tr bgcolor=\"#353c44\" >");
    arr.push("<td width=\"5%\"  style='text-align: center;'><input type=\"checkbox\" name=\"ckfk\" id=\"ckfkcall\" onclick=\"at(this)\"/></td>");
  
    arr.push("<td width=\"120px\"  style='text-align: center;'><span class=\"STYLE1\">栋阁列表</span></td>");
    arr.push("<td width=\"80px\"  style='text-align: center;'>");
    arr.push("<span class=\"STYLE1\" >楼层</span>");
    arr.push("</td>");
    arr.push("<td width=\"80px\"  style='text-align: center;'>");
    arr.push("<span class=\"STYLE1\" >房号</span>");
    arr.push("</td>");
    arr.push("<td width=\"80px\"  style='text-align: center;'>");
    arr.push("<span class=\"STYLE1\">是否审核</span>");
    arr.push("</td>");
    arr.push("<td width=\"80px\"  style='text-align: center;'>");
    arr.push("<span class=\"STYLE1\">操作</span>");
    arr.push("</td>");
    arr.push("</tr>");

    var recordLength = record.length;
    for (var i = 0; i < recordLength; i++) {
        if (i % 2 == 0)
            arr.push("<tr bgcolor='#FFFFFF'>");
        else
            arr.push("<tr bgcolor='#EEEDED'>");

        arr.push("<td height='20' class='STYLE6'  style='text-align: center;'>");
        arr.push("<input type='checkbox' name='checkbox_" + record[i].id + "' id='" + record[i].id + "' onclick=\"atsl( this," + record[i].id + ")\" />");
        arr.push("</td>");
        arr.push("<td height='20' style='text-align: center;'>");
        arr.push(record[i].bname);
            arr.push("</td>");

            arr.push("<td height='20' class='STYLE6'  style='text-align: center;'>");
        arr.push(record[i].floor);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        arr.push(record[i].name);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        if (record[i].isvalid == 0)
            arr.push("(已审)");
        else if (record[i].isvalid == 1)
            arr.push("(待审核)");
        else if (record[i].isvalid == 2)
            arr.push("(未审)");
        arr.push("</td>");

        if (hCompetencesIsEdit == 1 && hCompetencesIsOtherName == 1) {
            arr.push("<td height='20' class='STYLE6'>");

            arr.push("<a href='javascript:SI(" + record[i].id + ")'>修改</a>");
            if (hCompetencesIsDel == 1) {//系统管理员删除栋阁
                arr.push("<a href='javascript:showT_roomno_type(1," + record[i].id + ")'>删除</a>");
            }
            arr.push("</td>");
        } 
        else if (hCompetencesIsEdit == 1 && hCompetencesIsOtherName == 0) {
            arr.push("<td height='20' class='STYLE6'>");
            arr.push("<a href='javascript:SI(" + record[i].id + ")'>修改</a>");
            arr.push("</td>");
        } 
        arr.push("</tr>");
    }
    arr.push("</table>");
    arr.push("<div id=\"div7Page\" ></div>");
    //$("#div7").html(arr.join('')); // 显示列表
    document.getElementById('div7').innerHTML = arr.join('');
    //document.getElementById('divcount').innerHTML = '共:' + currentPage + '条';


    


    $("#div7Page").html(""); // 清空
    if (pageall > 1) {
        var pageHtml = LexunJS.showPage2(currentPage, pageall, "showT_roomno"); // 分页
        $("#div7Page").html(pageHtml);
    }
}

// 栋阁详情
function showBuild(currentPage) {
    var eid = $("#hID").val();
    var name = $("#hEstateName").val();
    var hid = $("#hidid").val();                    // 楼盘名称
    if (name == "拼音均可" || $("#iEstateName").val() == "") {
        name = "";
    }
   
    if (eid <= 0) return;
    
    $("#div2").html("<img src=\"../images/loading.gif\" />"); // 清空列表 
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerIndex.ashx',
        data: 'act=build_list&name='+name+'&hid='+hid+'&page=' + currentPage + '&pagesize=' + pageSize + '&id=' + eid,
        timeout: '10000',
        error: function() {
            alert("查询失败！");
        },
        success: function(json) {
            showBuildCallBack(json);
        }
    });
}

function showBuildCallBack(response) {  
    var json = eval("(" + response + ")");
    var record = json.record;

    var page = json.page;

    currentPage = page.currentpage;
    pageall = parseInt(page.pageall);
    total = page.total;

    // 权限判断
    var hCompetencesIsAdd = $("#hCompetencesIsAdd").val();                  // 0不允许添加 1允许添加
    var hCompetencesIsEdit = $("#hCompetencesIsEdit").val();                // 0不允许修改 1允许修改
    var hCompetencesIsOtherName = $("#hCompetencesIsOtherName").val();      // 0不允许申请别名 1允许申请别名
    var RoleId = document.getElementById("hRoleId").value;  //删除栋阁

    var hCompetencesIsDel = $("#hCompetencesIsDel").val();      // 0不允许申请别名 1允许申请别名
    var arr = [];
    arr.push("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" >");
    arr.push("<tr bgcolor=\"#353c44\" >");
    arr.push("<td width=\"75%\"><span class=\"STYLE1\">&nbsp;栋阁列表</span></td>");
    arr.push("<td>");
    if (hCompetencesIsAdd == 1) {
        arr.push("<img src=\"../images/add.gif\" height=\"10\" />");
        arr.push("<span class=\"STYLE1\" onclick=\"buildDialog()\">添加栋阁</span>");
        arr.push("&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"STYLE1\" onclick=\"buildDialogBatch()\">批量添加栋阁房号</span>");

    }
    arr.push("</td>");
    arr.push("<td>");

    // 批量申请别名
    //            if (hCompetencesIsOtherName == 1) {
    //                arr.push("<img src=\"../images/add.gif\" height=\"10\" />");
    //                arr.push("<span class=\"STYLE1\" onclick=\"addVolume()\">批量申请别名</span>");
    //            }

    arr.push("</td>");
    arr.push("</tr>");
    arr.push("</table>");

    arr.push("<table id='table1' width='100%' border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'>");
    arr.push("<tr>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("<input type=\"checkbox\" name=\"checkboxAll\" id=\"checkboxAll\" onclick=\"cbSelectAll()\" />");
    arr.push("</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE6'>");
    arr.push("栋阁名称");
    arr.push("</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE6'>");
    arr.push("总层数");
    arr.push("</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE6'>");
    arr.push("房号");
    arr.push("</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE6'>");
    arr.push("状态");
    arr.push("</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE6'>");
    arr.push("类型");
    arr.push("</td>");

    if (hCompetencesIsEdit == 1 || hCompetencesIsOtherName == 1) {
        arr.push("<td height='25' bgcolor='d3eaef' class='STYLE6'>");
        arr.push("基本操作");
        arr.push("</td>");
    }
    arr.push("</tr>");

    var recordLength = record.length;
    for (var i = 0; i < recordLength; i++) {
        if (i % 2 == 0)
            arr.push("<tr bgcolor='#FFFFFF'>");
        else
            arr.push("<tr bgcolor='#EEEDED'>");

        arr.push("<td height='20' class='STYLE6'>");
        arr.push("<input type='checkbox' name='checkbox_" + record[i].id + "' id='" + record[i].id + "' onclick=\"cbSelect(this, " + record[i].id + ")\" />");
        arr.push("</td>");
        arr.push("<td height='20' style='text-align: left;'>");
        arr.push(record[i].name);
        if (record[i].othername != "")
            arr.push("(" + record[i].othername + ")</td>");

        arr.push("<td height='20' class='STYLE6'>");
        arr.push(record[i].floortotal);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        arr.push("<a href='javascript:roomNoDialog(" + record[i].id + ")'>进入>></a>");
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        if (record[i].isvalid == 0)
            arr.push("(有效)");
        else if (record[i].isvalid == 1)
            arr.push("(待审核)");
        else if (record[i].isvalid == 2)
            arr.push("(无效)");
        arr.push("</td>");
        arr.push("<td height='25' class='STYLE6'>");
        arr.push(record[i].type);
        arr.push("</td>");


       if (hCompetencesIsEdit == 1 && hCompetencesIsOtherName == 1 ) {
            arr.push("<td height='20' class='STYLE6'>");
            arr.push("<a href='javascript:add(" + record[i].id + ")'>申请别名</a> ");
            arr.push("<a href='javascript:buildDialog(" + record[i].id + ")'>修改</a>");
            if (hCompetencesIsDel == 1) {//系统管理员删除栋阁
                arr.push("<a href='javascript:DropBuild(" + record[i].id + ",1)'>删除</a>");
            }
            arr.push("</td>");
        } else if (hCompetencesIsEdit == 1 && hCompetencesIsOtherName == 0) {
            arr.push("<td height='20' class='STYLE6'>");
            arr.push("<a href='javascript:buildDialog(" + record[i].id + ")'>修改</a>");
            arr.push("</td>");
        } else if (hCompetencesIsEdit == 0 && hCompetencesIsOtherName == 1) {
            arr.push("<td height='20' class='STYLE6'>");
            arr.push("<a href='javascript:add(" + record[i].id + ")'>申请别名</a> ");
            arr.push("</td>");
        } 
       

        arr.push("</tr>");
    }
    arr.push("</table>");
    arr.push("<div id=\"div2Page\" ></div>");

    $("#div2").html(arr.join('')); // 显示列表

    $("#div2Page").html(""); // 清空
    if (pageall > 1) {
        var pageHtml = LexunJS.showPage2(currentPage, pageall, "showBuild"); // 分页
        $("#div2Page").html(pageHtml);
    }
}

// 单选
function cbSelect(obj, objvalue) {
    if (obj.checked) {
        LexunJS.addOrCutData(1, "hBuildID", objvalue);
    }
    else {
        LexunJS.addOrCutData(0, "hBuildID", objvalue);
    }
}
function atsl(obj, objvalue) {
    if (obj.checked) {
        LexunJS.addOrCutData(1, "hidckfk", objvalue);
    }
    else {
        LexunJS.addOrCutData(0, "hidckfk", objvalue);
    }
}
// 全选
function cbSelectAll() {
    document.getElementById("hBuildID").value = "";
    var cbAll = document.getElementById("checkboxAll");
    var checkList = document.getElementsByTagName("input");

    if (cbAll.checked) {
        for (var i = 0; i < checkList.length; i++) {
            if (checkList[i].type == "checkbox") {
                checkList[i].checked = true;
                if (parseInt(checkList[i].id) > 0) LexunJS.addOrCutData(1, "hBuildID", checkList[i].id);
            }
        }
    }
    else {
        for (var i = 0; i < checkList.length; i++) {
            if (checkList[i].type == "checkbox") {
                checkList[i].checked = false;
                if (parseInt(checkList[i].id) > 0) LexunJS.addOrCutData(0, "hBuildID", checkList[i].id);
            }
        }
    }
}
function at(obj) {

    document.getElementById("hidckfk").value = "";
    var cbAll = document.getElementById("ckfkcall");
    var checkList = document.getElementsByTagName("input");

    if (cbAll.checked) {
        for (var i = 0; i < checkList.length; i++) {
            if (checkList[i].type == "checkbox") {
                checkList[i].checked = true;
                if (parseInt(checkList[i].id) > 0) LexunJS.addOrCutData(1, "hidckfk", checkList[i].id);
            }
        }
    }
    else {
        for (var i = 0; i < checkList.length; i++) {
            if (checkList[i].type == "checkbox") {
                checkList[i].checked = false;
                if (parseInt(checkList[i].id) > 0) LexunJS.addOrCutData(0, "hidckfk", checkList[i].id);
            }
        }
    }
}

// 查看出售｜出租房源
function showHousing(currentPage) {
    var eid = $("#hID").val();
    if (eid <= 0) return;

    var tradetype = $("#hTradeTypeID").val();
    var divId = "div3";
    if (tradetype == 2)
        divId = "div4";

    $("#" + divId).html("<img src=\"../images/loading.gif\" />"); // 清空列表 
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerHousing.ashx',
        data: 'act=housing_list_bytradetype&page=' + currentPage + '&pagesize=' + pageSize + '&eid=' + eid + '&tradetype=' + tradetype,
        timeout: '10000',
        error: function() {
            alert("查询失败！");
        },
        success: function(json) {
            showHousingCallBack(json);
        }
    });
}

function showHousingCallBack(response) {
    var json = eval("(" + response + ")");
    var record = json.record;

    var tradetype = $("#hTradeTypeID").val();
    var divId = "div3";
    if (tradetype == 2)
        divId = "div4";

    if (record == null || record.length == 0) {
        $("#" + divId).html("<font color='red'>&nbsp;系统内暂无您查询的信息!</font>");
        return;
    }

    var page = json.page;

    currentPage = page.currentpage;
    pageall = parseInt(page.pageall);
    total = page.total;

    var arr = [];
    arr.push("<table id='table1' width='100%' border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'>");
    arr.push("<tr>");
    arr.push("<td height='25' class='STYLE6'>");
    arr.push("盘源编号");
    arr.push("</td>");
    arr.push("<td height='25' class='STYLE6'>");
    arr.push("栋阁名称");
    arr.push("</td>");
    arr.push("<td height='25' class='STYLE6'>");
    arr.push("房号");
    arr.push("</td>");
    arr.push("<td height='25' class='STYLE6'>");
    arr.push("城区");
    arr.push("</td>");
    arr.push("<td height='25' class='STYLE6'>");
    arr.push("片区");
    arr.push("</td>");
    arr.push("<td height='25' class='STYLE6'>");
    arr.push("用途");
    arr.push("</td>");
    arr.push("<td height='25' class='STYLE6'>");
    arr.push("房");
    arr.push("</td>");
    arr.push("<td height='25' class='STYLE6'>");
    arr.push("厅");
    arr.push("</td>");
    arr.push("<td height='25' class='STYLE6'>");
    arr.push("面积");
    arr.push("</td>");
    arr.push("<td height='25' class='STYLE6'>");
    arr.push("总价");
    arr.push("</td>");
    arr.push("<td height='25' class='STYLE6'>");
    arr.push("盘源状态");
    arr.push("</td>");
    arr.push("</tr>");

    var recordLength = record.length;
    for (var i = 0; i < recordLength; i++) {
        if (i % 2 == 0)
            arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#FFFFFF' style='cursor: pointer;'  >");
        else
            arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#EEEDED' style='cursor: pointer;'  >");

        arr.push("<td height='20' class='STYLE6'>");
        arr.push(record[i].id);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        arr.push("<a href=\"javascript:showHousingDialog(" + record[i].id + ")\" >" + record[i].buildname + "</a></td>");
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        arr.push(record[i].roomno);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        arr.push(record[i].dname);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        arr.push(record[i].area);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        arr.push(LexunJS.GetUsageNameById(record[i].use));
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        arr.push(record[i].room);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        arr.push(record[i].hall);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        arr.push(record[i].acreage);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        arr.push(record[i].totalprice);
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'><font color='red'>");
        if (record[i].status == 1)
            arr.push("当前盘");
        else if (record[i].status == 2)
            arr.push("资料盘");
        else if (record[i].status == 3)
            arr.push("无效盘");

        if (record[i].isvalid == 0)
            arr.push("(有效)");
        else if (record[i].isvalid == 1)
            arr.push("(待审核)");
        else if (record[i].isvalid == 2)
            arr.push("(无效)");
        arr.push("</font></td>");
    }
    arr.push("</table>");
    arr.push("<div id=\"" + divId + "Page\" ></div>");
    $("#" + divId).html(arr.join('')); // 显示列表

    $("#" + divId + "Page").html(""); // 清空
    if (pageall > 1) {
        var pageHtml = LexunJS.showPage2(currentPage, pageall, "showHousing"); // 分页
        $("#" + divId + "Page").html(pageHtml);
    }
}

// 弹出窗口,查看某匹配出的房源详细
function showHousingDialog(id) {
    var path = "../PM/HousingDetail.aspx?id=" + id;
    var parameter = "房源详情";
    var style = "left = 50, screenX = 0, top = 50, screenY = 0, resizable = yes, scrollbars = yes,width=750px, height=500px,Toolbar=no,Location=no,Direction=no,Resizeable=no";

    window.open(path, parameter, style);
}

// 1小区照片 2户型照片
function showEstatePic(typeid, divId) {
    var eid = $("#hID").val();
    if (eid <= 0) return;
    phototype = typeid;
    $("#" + divId).html("<img src=\"../images/loading.gif\" />"); // 清空列表 
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerIndex.ashx',
        data: 'act=estatepic_list&eid=' + eid + '&type=' + typeid,
        timeout: '10000',
        error: function() {
            alert("查询失败！");
        },
        success: function(json) {
            showEstatePicCallBack(json, divId);
        }
    });
}

function showEstatePicCallBack(response, divId) {
    var json = eval("(" + response + ")");
    var record = json.record;
    var duserid = document.getElementById("iuserid").value;
    var ideptid = document.getElementById("ideptid").value;
    var hAllowOutsidePhotoCount = document.getElementById("hAllowOutsidePhotoCount").value;
    var hAllowRoomfigureCount = document.getElementById("hAllowRoomfigureCount").value;
    var recordLength = record.length;
    var photocount = 0;
    var arr = [];
    arr.push("<ul class='youxi_left_ul'>");
    for (var i = 0; i < recordLength; i++) {

        arr.push("<li>");
        arr.push("<a href='javascript:showPhotoDetail(" + record[i].eid + "," + record[i].type + "," + i + ")'><img id='img" + record[i].id + "' style='width:120px;' src='../" + record[i].picurl + "' /></a>");
        arr.push("<br/>" + record[i].remark + "   <br/>上传人:" + record[i].user + "[" + record[i].dept + "]<br/>上传时间:" + record[i].createtime)
        if (document.getElementById("hCompetenDelPic").value == 1 || duserid == record[i].userid) {//判断是否有权限删除图片
            arr.push("<a href=\"javascript:DelPic(" + record[i].id + "," + record[i].userid + ");\">删除</a>");
        }
        arr.push("</li>");
        photocount++;
    }
    arr.push("</ul>");

    //            if (divId == "div5")
    //                arr.push("<ul><a href=\"javascript:ShowDialog(1);\"><strong><font color='red'>上传小区照片</font></strong></a><ul>");
    //            else
    //                arr.push("<ul><a href=\"javascript:ShowDialog(2);\"><strong><font color='red'>上传小区户型</font></strong></a><ul>");

    $("#" + divId).html(arr.join('')); // 显示列表

    if (phototype == 1 && photocount > hAllowOutsidePhotoCount)
        $("#HLUpload1").hide();
    else if (phototype == 2 && photocount > hAllowRoomfigureCount)
        $("#HLUpload2").hide();
    

}
function DelPic(id, userid) {//删除图片
    hiConfirm("您确定要删除该图片，请谨慎操作！", "确认框", function(result) {
        if (result) {
            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerIndex.ashx',
                data: 'act=DelPic&id=' + id + '&userid=' + userid,
                timeout: '10000',
                error: function() {
                    alert("系统繁忙，请稍候后试！");
                },
                success: function(json) {
                    alert(json);
                    //alert(json);

                    if (phototype == 1)
                        go_to(5);
                    else
                        go_to(6);
                }
            });
        }
    });
}

///删除栋阁 1单项删除 2是批量删除 3是审核
function DropBuild(id, type) {
    if (id != 0) {
        hiConfirm("您确定要删除该栋阁，请谨慎操作！", "确认框", function(result) {
            if (result) {
                $.ajax({
                    type: 'POST',
                    url: '../Handler/HandlerIndex.ashx',
                    data: 'act=UpdateBuild&type=1&id=' + id,
                    timeout: '10000',
                    error: function() {
                        alert("系统繁忙，请稍候后试！");
                    },
                    success: function(json) {
                        alert(json);
                        showBuild(currentPage);
                    }
                });
            }
        });
    }
    if(type==2) {
        if (document.getElementById('hBuildID').value != "") {
            hiConfirm("您确定要批量删除栋阁，请谨慎操作！", "确认框", function(result) {
                if (result) {
                    $.ajax({
                        type: 'POST',
                        url: '../Handler/HandlerIndex.ashx',
                        data: 'act=UpdateBuild&type=2&id=' + document.getElementById('hBuildID').value,
                        timeout: '10000',
                        error: function() {
                            alert("系统繁忙，请稍候后试！");
                        },
                        success: function(json) {
                            alert(json);
                            showBuild(currentPage);
                        }
                    });
                }
            });
        }
    }
    if (type == 3) {
        if (document.getElementById('hBuildID').value != "") {
            hiConfirm("您确定要审核栋阁，请谨慎操作！", "确认框", function(result) {
                if (result) {
                    $.ajax({
                        type: 'POST',
                        url: '../Handler/HandlerIndex.ashx',
                        data: 'act=UpdateBuild&type=3&id=' + document.getElementById('hBuildID').value,
                        timeout: '10000',
                        error: function() {
                            alert("系统繁忙，请稍候后试！");
                        },
                        success: function(json) {
                            alert(json);
                            showBuild(currentPage);
                        }
                    });
                }
            });
        }
    }
  }

function showPhotoDetail(eid, typeid, num) {
    var path = "EstatePicDetail.aspx?eid=" + eid + "&typeid=" + typeid + "&num=" + num;
    var parameter = "楼盘图片";
    var style = "dialogWidth:600px; dialogHeight:550px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";

    window.showModalDialog(path, parameter, style);
}

//允许上传的相片总量
//弹出窗口 1小区照片 2户型照片
function ShowDialog(typeid) {
    var id = LexunJS.GetQueryString("id");
    var typename = "estate";
    var path = "SelectBuild.aspx?type=" + typeid + "&eid=" + id + "&typename=" + typename;
    var parameter = "";
    var style = "dialogWidth:538px; dialogHeight:563px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";
    window.showModalDialog(path, parameter, style);
    if(typeid==1)
        go_to(5);
    else
        go_to(6);
}

// 打开高级查询框
function iAdvancedSearch_onclick() {
    var obj = document.getElementById("divAdvancedSearch");
    $("#divAdvancedSearch").toggle();
}

// 更新楼盘状态，该楼盘字典整理完成
function upateEstate() {
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerIndex.ashx',
        data: 'act=upateEstate&id=' + document.getElementById('hID').value,
        timeout: '10000',
        error: function() {
            alert("系统繁忙，请稍候后试！");
        },
        success: function(json) {
            alert(json);
        }
    });

    return false;
}